<!DOCTYPE html>
<!--
Author: Atef Sami
-->
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <link rel="stylesheet" type="text/css" href="style3.css"/>
        <?php include "jquery.php"; ?>
        <script type="text/javascript" src="calendar.js"></script>
        <script type="text/javascript">
            function init(ID) {
                //add date picker to each date field
                calendar.set(ID);
            }
            // wait for the document to be ready before starting the script
            $(document).ready(function(){
                $("#shortpapercheckbox").bind("click",function()
                {
                    if($(this).is(":checked"))
                        $("#shortpapersubmissiondate").removeAttr("disabled");
                    else
                        $("#shortpapersubmissiondate").attr("disabled","disabled");
                });
                $("#longpapercheckbox").bind("click",function()
                {
                    if($(this).is(":checked"))
                        $("#longpapersubmissiondate").removeAttr("disabled");
                    else
                        $("#longpapersubmissiondate").attr("disabled","disabled");
                });

                $("#Image").bind("click",function()
                {
                    if($(this).is(":checked"))
                        $("#imagesubmissiondate").removeAttr("disabled");
                    else
                        $("#imagesubmissiondate").attr("disabled","disabled");
                });

                $("#Video").bind("click",function()
                {
                    if($(this).is(":checked"))
                        $("#videosubmissiondate").removeAttr("disabled");
                    else
                        $("#videosubmissiondate").attr("disabled","disabled");
                });

                $("#Poster").bind("click",function()
                {
                    if($(this).is(":checked"))
                        $("#postersubmissiondate").removeAttr("disabled");
                    else
                        $("#postersubmissiondate").attr("disabled","disabled");
                });
                $("#other").bind("click",function()
                {
                    if($(this).is(":checked"))
                        $("#othersubmissiondate,#custom_type").removeAttr("disabled");
                    else
                        $("#othersubmissiondate,#custom_type").attr("disabled","disabled");
                });

                $("#custom_committee").bind("click",function()
                {
                    if($(this).is(":checked"))
                        $("#custom_text").removeAttr("disabled");
                    else
                        $("#custom_text").attr("disabled","disabled");
                });
                $("#Submitbutton").bind('click',function(){

                    // stores the string from the text area and stores it in a new variable
                    longname = $("#LongName").val();
                    shortname = $("#Shortname").val();
                    textareadescription = $("#description").val();
                    //check if the checkbox is checked , and returns either true (in case checkbox checked  )else it returns false
                    spaper = $("#shortpapercheckbox").is(':checked');
                    lpaper = $("#longpapercheckbox").is(':checked');
                    spapersub = $("#shortpapersubmissiondate").val();
                    lpapersub=$("#longpapersubmissiondate").val();
                    isub=$("#imagesubmissiondate").val();
                    vsub=$("#videosubmissiondate").val();
                    psub=$("#postersubmissiondate").val();
                    //check if the checkbox is checked , it returns either true or false
                    com1 =  $("#committe1checkbox").is(':checked');
                    com2 = $("#committe2checkbox").is(':checked');
                    com3 = $("#committe3checkbox").is(':checked');
                    custom_com=$("#custom_committee").is(":checked");
                    customcomtext=$("#custom_text").val();
                    papertype =$("#papertypes").val();
                    conference =$("#previousconf").val();
                    image=$("#Image").is(":checked");
                    video=$("#Video").is(":checked");
                    poster=$("#Poster").is(":checked");
                    other=$("#other").is(":checked");
                    custom_type=$("#custom_type").val();
                    place=$("#place").val();
                    if (longname != "" && shortname != "" && place != "")
                    {
                        if(spaper == true | lpaper == true | image == true | video == true | poster == true | other == true)
                        {
                            if (com1 == true | com2 == true | com3 == true | other == true)
                            {

                                $.post("conferenceSetupServerSide.php",{longname: longname , shortname: shortname ,place:place, textarea: textareadescription ,image:image,video:video,poster:poster, Spaper: spaper , Lpaper: lpaper , spapersub: spapersub,lpapersub:lpapersub,isub:isub,vsub:vsub,psub:psub ,comm1: com1 , comm2: com2 , comm3: com3 ,other:other,custom_type:custom_type,custom_com: custom_com,custom_com_text:customcomtext, papertype: papertype , conference: conference },function(data)  //sending all the page values to the server while storing them in new variables
                                {
                                    // this checks that if there are any errors that were found then it should be alerted and the function stops. Else there are no errors in the data will be alerted then it will direct the user to the main menu.
                                    if(data.indexOf("Error")==0)
                                    {
                                        alert(data);
                                    }
                                    else
                                    {
                                        // if no error ocuured redirect to the main page
                                        alert(data);
                                        top.window.location= 'main.php';

                                    }
                                })
                            }
                            else
                            {
                                alert('please make sure that you chose a committee')
                            }
                        }
                        else
                        {
                            alert (' please make sure that you have chosen a submission type');
                        }
                    }
                    else {
                        alert(' place make sure that you entered the long conference name or the short conference name or place successfully');
                    }
                });

            });
        </script>
        <script typ="text/javascript">
            function validateDate(date)
            {
                now= new Date(); // this now variable  takes a date variable and it is supposed to get the local date
                regexpDate=/^\d{4}(-|\/)([1-9]|0[1-9]|1[0-2])(-|\/)([1-9]|0[1-9]|[1-2][0-9]|3[0-1])$/; // i am making a regular expression that checks on the following :  first this sign ^  means that i am looking from the beginning of  string , d{4} means that i am making 4 characters that are numbers in order for the user to be able to enter the year then it is followed by a - or / which are allowed  then it should be followed by months so i wrote that if he enters a month starting from 0 to 9  or the first starting character is 0 followed  then by numbers from 0 to 9 or  the first character is 1 followed by numbers from 0 to 2(this checks that the users chooses a right month number) , then i am making sure again that there is a - or /  that is followed  by the right date number  then i entered the $ sign which means the end of the text area  and this was to make sure that this regular expression is read from the start till the end of the text area
                if(date.match(regexpDate)==null) // i am making sure that the date is not null
                    return false;
                else
                {
                    /* this arr function will split at each - or / that he finds
                    this new variable is  take an array of dates (which means that arr[0] takes the year that the user has entered followed by arr[1]-1 that takes the monthes but since the array takes it from 0 till 11 i used the -1, arr[3] takes the date
                    checking that input dates are  not older than the local date */
                    arr=date.split(/[-|\/]+/);
                    input=new Date(arr[0],arr[1]-1,arr[2]);
                    if(input<now)
                        return false;
                    else
                        return true;
                }
            }
        </script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title> Conference Setup</title>
    </head>
    <body>
        <!-- created a legend in order to have all the labels and buttons stored in an organized shape  -->
    <legend><b>Conference Setup</b></legend>
    <!-- created a label followed b a text area in order for the member to enter the specified data  -->
    <label><b>Long Conference Name:</b></label>
    <input type="text" size="40" id="LongName" /><br />
    <label><b>Short Conference Name:</b></label>
    <input type="text" size="25" id="Shortname" /><br />
    <label><b>Description:</b></label><br/>
    <textarea rows="6" cols="70" id="description"></textarea><br/>
    <!-- created a drop down list that states the scientific areas and  added some data to the drop down list (e.g. science fiction part , normally this part gets  this part from the database since it is hardb coded in the database -->
    <label><b>Scientific area:</b></label>
    <select id="papertypes">
        <optgroup label="Paper types">
            <?php
            $con = mysql_connect("localhost", "root", "");
            if (!$con)
            {
                echo "not connected to local host";
            }
            else
            {
                mysql_select_db("mydb", $con);
                $query = mysql_query("SELECT area_of_expertise_text  FROM area_of_expertise ");  //  getting all area of expertis from database and assgning them in a new value
                // fetching  the area of expertise  and insert it in a row then i echo each new row n a seperate line
                while ($row = mysql_fetch_assoc($query))
                {
                    echo "<option>" . $row["area_of_expertise_text"] . "</option>";
                }
            }
            ?>
        </optgroup>
    </select><br/>
    <!-- created a drop down list which show a list of all the created conferences in it  -->
    <label><b>Link to previous conferences:</b></label>
    <select id="previousconf">
        <optgroup label="previous conferences">
            <?php
            $con = mysql_connect("localhost", "root", "");
            //checking it it connected to database or not
            if (!$con)
            {
                echo " Not connected in database";
            }
            else
            {
                // getting all the names of the created conferences that were stored in database
                mysql_select_db("mydb", $con);
                $query = mysql_query("SELECT long_name FROM conference", $con);
                // putting each conference name in the drop down list and in a new line
                while ($row = mysql_fetch_assoc($query))
                {
                    echo "<option>" . $row["long_name"] . "</option>";
                }
            }
            ?>
        </optgroup>
    </select><br/>
    Place: <input type="text" name="place" id="place" value=""/><br/>
    <!-- created a table in order to help the user  to choose the required paper types that his conference will support while providing him with an area to set the date -->
    <label><b>Submission types:</b></label><br/>
    <table border="1">
        <tr>
            <th>  </th>
            <th>  </th>
            <th><b>Paper submission date</b></th>
        </tr>
        <tr>
            <!-- created a checkbox for short paper  and gave it an id in order to use it in the above script -->
            <td> <input type="checkbox" name="shortpaper" id="shortpapercheckbox"/></td>
            <td> <label for="shortpaper"><b>Short Paper</b></label></td>
            <td> <input disabled="true" type="text" size="10" id="shortpapersubmissiondate" onfocus="javascript: init('shortpapersubmissiondate');"/> Date format yyyy-mm-dd</td>
        </tr>
        <tr>
            <!-- created a check box for long paper and gave it an id in order to use it in the above script -->
            <td> <input type="checkbox" name="longpaper" id="longpapercheckbox"/></td>
            <td> <label for="longpaper"><b>Long Paper</b></label></td>
            <td> <input disabled="true" type="text" size="10" id="longpapersubmissiondate" onfocus="javascript: init('longpapersubmissiondate');"/> Date format yyyy-mm-dd</td>
        </tr>
        <tr>
            <!-- created a check box for Image and gave it an id in order to use it in the above script -->
            <td> <input type="checkbox" name="Image" id="Image"/></td>
            <td> <label for="Image"><b>Images</b></label></td>
            <td> <input disabled="true" type="text" size="10" id="imagesubmissiondate" onfocus="javascript: init('imagesubmissiondate');"/> Date format yyyy-mm-dd</td>
        </tr>
        <tr>
            <!-- created a check box for video and gave it an id in order to use it in the above script -->
            <td> <input type="checkbox" name="Video" id="Video"/></td>
            <td> <label for="Video"><b>Videos</b></label></td>
            <td> <input disabled="true" type="text" size="10" id="videosubmissiondate" onfocus="javascript: init('videosubmissiondate');"/> Date format yyyy-mm-dd</td>
        </tr>
        <tr>
            <!-- created a check box for poster and gave it an id in order to use it in the above script -->
            <td> <input type="checkbox" name="Poster" id="Poster"/></td>
            <td> <label for="Poster"><b>Posters</b></label></td>
            <td> <input disabled="true" type="text" size="10" id="postersubmissiondate" onfocus="javascript: init('postersubmissiondate');"/> Date format yyyy-mm-dd</td>
        </tr>
        <tr>
            <!-- created a check box for Other and gave it an id in order to use it -->
            <td> <input type="checkbox" name="other" id="other"/></td>
            <td> <label for="other"><b>Custom type</b></label><input disabled="true" type="text" name="custom_type" id="custom_type"/></td>
            <td> <input disabled="true" type="text" size="10" id="othersubmissiondate" onfocus="javascript: init('othersubmissiondate');"/> Date format yyyy-mm-dd</td>
        </tr>
    </table>
    <!-- created a table with no borders and inserted the 3 types of committees in it so the member can choose one -->
    <label><b>Committee types:</b></Label><br/>
    <table>
        <tr>
            <th>  </th>
            <th>  </th>
        </tr>
        <tr>
            <!-- created a check box for committee1  and gave it an id in order to use it in the above script -->
            <td> <input type="checkbox" name="committee1" id="committe1checkbox"/></td>
            <td> <label for="committee1"><b>Paper Review Committee</b></label></td>
        </tr>
        <tr>
            <!-- created a check box for committee2  and gave it an id in order to use it in the above script -->
            <td> <input type="checkbox" name="committee2" id="committe2checkbox"/></td>
            <td> <label for="committee2"><b>Quality Control Committee</b></label></td>
        </tr>
        <tr>
            <!-- created a check box for committee3  and gave it an id in order to use it in the above script -->
            <td> <input type="checkbox" name="committee3" id="committe3checkbox" /></td>
            <td> <label for="committee3"><b>category review committee</b></label></td>
        </tr>
        <tr>
            <!-- created a check box for custom committee  and gave it an id in order to use it-->
            <td><input type="checkbox" name="custom_committee" id="custom_committee"/></td>
            <td><label for="custom_committee"><b>Custom committee</b></label><input disabled="true" type="text" id="custom_text" name="custom_text" value=""/></td>
        </tr>
    </table><br/>
    <!-- created a submit button and gave it an id so i can use it in the script above -->
    <button id="Submitbutton"><b>Submit</b></button>
    <?php
// End of documentation
    ?>
</body>
</html>
